<?php

class Administration_Model_Games extends Ehl_Model_Abstract
{
    protected $id;
    protected $idTeamHome;
    protected $idTeamVisitor;
    protected $idLocation;
    protected $date;
    protected $scoreHomeFirst;
    protected $scoreHomeSecond;
    protected $scoreHomeThird;
    protected $scoreHomeOvertime;
    protected $scoreHomeShoutout;
    protected $scoreVisitorFirst;
    protected $scoreVisitorSecond;
    protected $scoreVisitorThird;
    protected $scoreVisitorOvertime;
    protected $scoreVisitorShoutout;
    protected $indexDisplay;
    protected $creationUser;
    protected $creationDate;

    public static function gameToDisplay()
    {
        $self = new self();
        $table = $self->_getMapper()->_getTable();
        $select = new Zend_Db_Table_Select($table);
        $select->where($self->_getMapper()->getDict("indexDisplay") . "=?", 1);
        $stmt = $select->query();
        $result = $stmt->fetch();
        $datas = $self->_getMapper()->unmap($result);
        return new Administration_Model_Games($datas);
    }

    public function listForSchedule( $idTeam )
    {
    	$dict = $this->_getMapper()->getDict();
    	$table = $this->_getMapper()->_getTable();
		$select = new Zend_Db_Table_Select($table);
		$select->where($dict['idTeamHome'] . "=?", $idTeam, Zend_Db::INT_TYPE);
		$select->orWhere($dict['idTeamVisitor'] . "=?", $idTeam, Zend_Db::INT_TYPE);
		$select->order($dict['date'] . " ASC");
		$select->group("YEAR(" . $dict['date'] . ")");
		$select->group("MONTH(" . $dict['date'] . ")");
		$stmt = $select->query();
		$result = $stmt->fetchAll();
		$result = $this->_getMapper()->unmapArray($result);
		foreach( $result as $datas ) {
			$objects[] = new Administration_Model_Games($datas['id']);
		}
		$games = array();
		foreach ( $objects as $game ) {
			$dateZend = new Jnd_Date($game->getDate());
			$games[$dateZend->get("MMMM Y")][] = $game;
		}
		
		return $games;
    }
}
